import os

from databases import Database
from sqlalchemy import Column, DateTime, Integer, MetaData, String, Table, create_engine
from sqlalchemy.sql import func

DATABASE_URL = os.getenv("DATABASE_URL")

# SQLAlchemy
engine = create_engine(str(DATABASE_URL))
metadata = MetaData()

recipes = Table(
    "recipes",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("title", String(64)),
    Column("cooking_time", Integer),
    Column("ingredients", String(1024)),
    Column("description", String(1024)),
    Column("view_count", Integer, server_default="0", nullable=False),
    Column("created_date", DateTime, default=func.now(), nullable=False),
)

# `databases` query builder
database = Database(str(DATABASE_URL))
